package common

import (
	"gorm.io/gorm"
	"organoid_public/domain/common/model"
	"organoid_public/domain/common/repository"
	"organoid_public/infrastructure/db"
)

type DictionaryDetailRepository struct {
	defaultDb *gorm.DB
}

func NewDictionaryDetailRepository(db db.DefaultDb) repository.DictionaryDetail {
	return &DictionaryDetailRepository{
		defaultDb: db,
	}
}

func (h *DictionaryDetailRepository) GetDictionaryEnum(name []string) ([]model.ConfigDictionaryDetail, error) {
	var detail []model.ConfigDictionaryDetail
	ctx := h.defaultDb.Model(&model.ConfigDictionaryDetail{}).
		//Debug().
		Where("dictionary_code in ?", name).
		Order("rank").
		Scan(&detail)
	if ctx.Error != nil {
		return nil, ctx.Error
	}
	return detail, nil
}
